package book;
public class FactorialSolution {
    public int fac(int n) {
        if (n == 0) return 1; // (1) 边界条件
        int pre = fac(n - 1); // (2) 递归调用
        return n * pre; 	  // (3) 递推结果
    }
    public static void main(String[] args) {
        // 演示：输出0到10的阶乘
        FactorialSolution sln = new FactorialSolution();
        for (int n = 0; n <= 10; n++) {
            int f = sln.fac(n);
            System.out.printf("%d!=%d\n", n, f);
        }
    }
}